/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package gui;

import javax.microedition.lcdui.*;
import conexion.*;
import ral.Real;

/**
 *
 * @author Pablo
 */
public class MiPosicion extends Canvas implements CommandListener {
    private int width,height;
   private int anchor = Graphics.TOP | Graphics.LEFT;
   private Real latitud, longitud;
   private MenuPrincipal mp;

    public MiPosicion(Real lat, Real lng, MenuPrincipal mp) {
        try {
            this.latitud = lat;
            this.longitud = lng;
            this.mp = mp;
            width = getWidth();
            height = getHeight();
	    setCommandListener(this);
	    // Add the Exit command
	    addCommand(new Command("Regresar", Command.BACK, 1));
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
    public void limpiaPantalla(Graphics g){
        g.setColor( 255, 255, 255 );
        g.fillRect( 0, 0, width, height );
    }
    /**
     * paint
     */
    public void paint(Graphics g) {
        limpiaPantalla(g);
        g.setColor(0, 0, 0);
        try {
            g.drawImage(Conexion.ObtenerMapa(width, height, latitud , longitud, 0), 0, 0, anchor);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Called when a key is pressed.
     */
    protected  void keyPressed(int keyCode) {
    }

    /**
     * Called when a key is released.
     */
    protected  void keyReleased(int keyCode) {
    }

    /**
     * Called when a key is repeated (held down).
     */
    protected  void keyRepeated(int keyCode) {
    }

    /**
     * Called when the pointer is dragged.
     */
    protected  void pointerDragged(int x, int y) {
    }

    /**
     * Called when the pointer is pressed.
     */
    protected  void pointerPressed(int x, int y) {
    }

    /**
     * Called when the pointer is released.
     */
    protected  void pointerReleased(int x, int y) {
    }

    /**
     * Called when action should be handled
     */
    public void commandAction(Command command, Displayable displayable) {
        if(command.getLabel().equals("Regresar")){
            mp.getMidlet().pantalla.setCurrent(mp);
        }
    }

    public MenuPrincipal getMp() {
        return mp;
    }

    public void setMp(MenuPrincipal mp) {
        this.mp = mp;
    }
}
